package com.feng.system.service.impl;

import com.feng.common.SystemConstants;
import com.feng.common.utils.StringUtils;
import com.feng.system.domain.SysUser;
import com.feng.system.mapper.SysUserMapper;
import com.feng.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户管理 服务实现
 *
 * @author RoyWang
 */
@Service
public class SysUserServiceImpl implements ISysUserService {

    @Autowired
    private SysUserMapper userMapper;

    @Override
    public List<SysUser> selectUserList(SysUser user) {
        return userMapper.selectUserList(user);
    }

    @Override
    public String checkUserNameUnique(SysUser user) {
        int deptId = StringUtils.isNull(user.getUserId()) ? 0 : user.getUserId();
        SysUser info = userMapper.checkUserNameUnique(user.getUserName());
        if (StringUtils.isNotNull(info) && info.getUserId() != deptId) {
            return SystemConstants.NOT_UNIQUE;
        }
        return SystemConstants.UNIQUE;
    }

    @Override
    public int insertUser(SysUser user) {
        return userMapper.insertUser(user);
    }

    @Override
    public int updateUser(SysUser user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteUserById(int userId) {
        return userMapper.deleteUserById(userId);
    }

    @Override
    public SysUser selectUserById(int userId) {
        return userMapper.selectUserById(userId);
    }
}
